<?php
declare (strict_types = 1);

namespace app\middleware;

use think\Request;
use think\Response;

class CrossDomain
{

    protected array $header = [
        'Access-Control-Allow-Credentials' => 'true',
        'Access-Control-Allow-Origin'      => '*',
        'Access-Control-Max-Age'           => 1800,
        'Access-Control-Allow-Methods'     => 'GET, POST, PUT, DELETE',
        'Access-Control-Allow-Headers'     => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',
    ];

    /**
     * 处理请求
     * @param Request       $request
     * @param \Closure      $next
     * @return Response
     */
    public function handle(Request $request, \Closure $next): Response
    {
        return $next($request)->header($this->header);
    }

}